/**
 * <pre>
 * @(#)TitleConfig.java 1.00 2009-8-25
 * 
 * Copyright (c) 1998, 2009 Regular Individual. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributor(s):
 *     Haixu Huang
 * </pre>
 **/
package cn.sh.huang.chart.config;

import java.awt.Color;
import java.awt.Font;
import java.awt.RenderingHints;

import cn.sh.huang.chart.ext.enumtype.Direction;
import cn.sh.huang.chart.ext.enumtype.Extension;
import cn.sh.huang.chart.ext.enumtype.Overflow;
import cn.sh.huang.chart.ext.enumtype.Position;
import cn.sh.huang.chart.ext.enumtype.Side;
import cn.sh.huang.chart.view.AbstractView;

/**
 * <pre>
 * TitleConfig ...
 * 
 * @version 1.0
 * </pre>
 */
public class TitleConfig extends AbstractConfig
{
    private static final Font DEFAULT_FONT = new Font("Dialog", Font.BOLD, 18);

    private String title = "";
    private Position p = Position.CENTER_TOP;
    private Direction d = Direction.NORTH;
    private Extension e = Extension.TANGENT;
    private Font font = DEFAULT_FONT;
    private Color color = Color.BLACK;
    private Object hint = RenderingHints.VALUE_TEXT_ANTIALIAS_ON;
    private Overflow o = Overflow.TAIL;

    /**
     * @param view
     */
    public TitleConfig(AbstractView view)
    {
        super(view);
    }

    /**
     * @return the color
     */
    public Color getColor()
    {
        return color;
    }

    /**
     * @return the direction
     */
    public Direction getDirection()
    {
        return d;
    }

    /**
     * @return the extension
     */
    public Extension getExtension()
    {
        return e;
    }

    /**
     * @return the font
     */
    public final Font getFont()
    {
        return font;
    }

    /**
     * @return the o
     */
    public Overflow getOverflow()
    {
        return o;
    }

    /**
     * @return the position
     */
    public final Position getPosition()
    {
        return p;
    }

    /**
     * @return the hint
     */
    public Object getTextRenderingHint()
    {
        return hint;
    }

    /**
     * @return the title
     */
    public final String getTitle()
    {
        return title;
    }

    /**
     * @param color
     *            the color to set
     */
    public void setColor(Color color)
    {
        this.color = color;
        this.update();
    }

    /**
     * @param d
     *            the direction to set
     */
    public void setDirection(Direction d)
    {
        this.d = d;
        this.update();
    }

    /**
     * @param e
     *            the extension to set
     */
    public void setExtension(Extension e)
    {
        this.e = e;
        this.update();
    }

    /**
     * @param font
     *            the font to set
     */
    public final void setFont(Font font)
    {
        this.font = font;
        this.update();
    }

    /**
     * @param o
     *            the o to set
     */
    public void setOverflow(Overflow o)
    {
        this.o = o;
        this.update();
    }

    /**
     * @param p
     *            the position to set
     */
    public final void setPosition(Position p)
    {
        this.p = p;
        if (p.onTheSide(Side.CENTER)) { // Set the default direction and extension of text by position
            setExtension(Extension.TANGENT);
            if (p.onTheSide(Side.TOP) || p.onTheSide(Side.BOTTOM)) {
                setDirection(Direction.NORTH);
            } else if (p.onTheSide(Side.LEFT)) {
                setDirection(Direction.WEST);
            } else if (p.onTheSide(Side.RIGHT)) {
                setDirection(Direction.EAST);
            }
        }
        this.update();
    }

    /**
     * @param hint
     *            the hint to set
     */
    public void setTextRenderingHint(Object hint)
    {
        this.hint = hint;
        this.update();
    }

    public void setTitle(String title)
    {
        this.title = title;
        this.update();
    }
}
